package cn.edu.nju.ws.sview.crawler;


import cn.edu.nju.ws.sview.rdf.URIResource;

/**
 * 爬虫队列元素，最低元素weight 0.
 * @author Gong Saisai
 *
 */
public class Element implements Comparable<Element>{
	 public static int LOW_WEIGHT = 0;
	 public static int NORMAL_WEIGHT = 1;
	 public static int LEVEL_1 = 2;
	 public static int LEVEL_2 = 3;
	 public static int LEVEL_3 = 4;
	 public static int HIGH_WEIGHT =7;
     private URIResource resource;
     private int weight;
     public Element(URIResource resource ,int weight){
    	 this.resource= resource;
    	 this.weight = weight;
     }
     
     public int getWeight(){
    	 return this.weight;
     }
     
     public URIResource getResource(){
    	 return this.resource;
     }
     
     public void setWeight(int weight){
    	 this.weight = weight;
     }

	@Override
	public int compareTo(Element element) {
		// TODO Auto-generated method stub
		if(element==null){
			if(this!=null)
				return -this.weight;
			else
				return 1;
		}
		else if(this==null)
			return element.getWeight();
		return element.getWeight()-this.weight;
	}
     
	public int hashCode(){
		return this.resource.hashCode()*31+weight;
	}
	
	public boolean equals(Object o){
		if(o instanceof Element){
			Element element = (Element)o;
			if(this.resource.equals(element.resource)&&this.weight==element.weight)
				return true;
		}
		return false;
	}
}
